﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace StudentsLinqQueries
{
    class Program
    {
        static void Main()
        {
            List<Student> students = new List<Student>();
            students.Add(new Student("Marin", "Atanasov", 22));
            students.Add(new Student("Petyr", "Subev", 23));
            students.Add(new Student("Didi", "Dilqnova", 56));
            students.Add(new Student("Asd", "Ase", 22));
            students.Add(new Student("Asd", "Asc", 22));
            students.Add(new Student("Wait", "What", 18));
            students.Add(new Student("Marin", "Bratanov", 16));
            students.Add(new Student("Marin", "Yavorov", 38));

            students.Where(x => x.FirstName.CompareTo(x.LastName) == -1).ToList().ForEach(x => Console.WriteLine(x));
            Console.WriteLine();

            var ageBetween18And24 =
                from student in students
                where student.Age >= 18 && student.Age <= 24
                select student;
            foreach (Student student in ageBetween18And24)
            {
                Console.WriteLine(student);
            }
            Console.WriteLine();

            students.OrderBy(x => x.FirstName).ThenBy(x => x.LastName).ToList().ForEach(x => Console.WriteLine(x));
            Console.WriteLine();

            var sortedStudents =
                from student in students
                orderby student.FirstName, student.LastName
                select student;
            foreach (Student student in sortedStudents)
            {
                Console.WriteLine(student);
            }
            Console.WriteLine();
        }
    }
}
